package weaver.interfaces.jjy.duss.action;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.jjy.duss.hr.HR015;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;


import java.util.HashMap;
import java.util.Map;

/**
 * @program: ecology-9-demo
 * @description: 合同续签推送SAP
 * @author: Dusongsong
 * @create: 2019-12-07
 */
public class WeaHRhtxqtsAction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        String requestid = requestInfo.getRequestid();
        baseBean.writeLog("请求ID" + requestid);
        baseBean.writeLog("调用WeaHRhtxqtsAction");
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        String requestname  = requestInfo.getRequestManager().getRequestname();
        rs.executeQuery("select * from " + tablename + " where requestid=?", requestid);
        baseBean.writeLog("select * from " + tablename + " where requestid=" + requestid);
        rs.next();
        //主表字段
        String ygh = Util.null2String(rs.getString("ygh"));//员工号
        String xm = Util.null2String(rs.getString("xm"));//姓名
        String bm = Util.null2String(rs.getString("bm"));//部门
        String gwvalue = Util.null2String(rs.getString("gwvalue"));//部门
        String zwmcvalue = Util.null2String(rs.getString("zwmcvalue"));//职务名称
        String zwcvalue = Util.null2String(rs.getString("zwcvalue"));//职务簇
        String zwxlvalue = Util.null2String(rs.getString("zwxlvalue"));//职务序列
        String htzzrq = Util.null2String(rs.getString("htzzrq"));//合同终止日期
        String rzrq = Util.null2String(rs.getString("rzrq"));//入职日期
        String ksrqxqh = Util.null2String(rs.getString("ksrqxqh"));//开始日期(续签后)
        String htlxvalue = Util.null2String(rs.getString("htlxvalue"));//续签合同类型
        String htzzrqxqh = Util.null2String(rs.getString("htzzrqxqh"));//合同终止日期（续签后）
        String htqx = Util.null2String(rs.getString("htqx"));//合同期限
        String htqddwvalue = Util.null2String(rs.getString("htqddwvalue"));//合同签订单位
        String ldhtmbvalue = Util.null2String(rs.getString("ldhtmbvalue"));//劳动合同模板

        //调用合同续签接口
        HR015 hr015 = new HR015();
        Map<String, String> map = new HashMap<>();
        map.put("IV_PERNR", ygh);
        map.put("PERNR", ygh);
        map.put("NACHN", xm);
        map.put("PLANS", gwvalue);
        map.put("ZHR_GWXL", zwxlvalue);
        map.put("ZHR_ZW", zwmcvalue);
        map.put("ZHR_ZWC", zwcvalue);
        map.put("DEPTN", bm);
        map.put("CTBEG", ksrqxqh);
        map.put("CTEDT", htzzrqxqh);
        map.put("CTTYP", htlxvalue);
        map.put("ZHR_QXM", htqx);
        map.put("ZHR_WRKPL", htqddwvalue);
        map.put("ZHR_HTMB", ldhtmbvalue);
        baseBean.writeLog("相关参数:" + map.toString());
        Map<String, String> resultMap = hr015.execute(map);
        try{
            String flag = (String)resultMap.get("flag");
            String message = (String)resultMap.get("message");
            baseBean.writeLog("SAP返回结果——flag:" + flag + ";message:" + message);
            if("s".equalsIgnoreCase(flag)){
                return Action.SUCCESS;
            }else {
                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent(message);
                return Action.FAILURE_AND_CONTINUE;
            }
        }catch(Exception e){
            e.printStackTrace();
            baseBean.writeLog("异常参考:" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent(e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
